const path = require("path");
module.exports = {
  devServer: {
    // host: "localhost",
    port: 8989,
    https: false,
    hotOnly: false,
    disableHostCheck: true,
    open: false, // 配置自动启动浏览器
    // hotOnly: true,
    proxy: {
      "/bing": {
        target: "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8",
        /*
          format: 非必须，返回数据类型
            - js 返回json
            - xml 返回xml
          idx： 非必须，请求图片截至天数
            - 0 今天
            - -1 截至中明天
            - 1 截至至昨天，类推
          n：必须，返回请求数量，1-8
          mkt：非必须，地区
            - zh-CN
            - ...
        */
        pathRewrite: {
          "^/bing": "",
        },
        // changeOrigin: true
      },

      "/lh": {
        target: "http://localhost:8888/",
        pathRewrite: {
          "^/lh": "",
        },
      },

      "/leetcode": {
        target: "https://leetcode-cn.com/graphql",
        pathRewrite: {
          "^/leetcode": "",
        },
      },
    },
  },
  publicPath: process.env.NODE_ENV === "production" ? "./" : "/",
  configureWebpack: {
    output: {
      // 把子应用打包成 umd 库格式
      library: `bundle`,
      libraryTarget: "umd",
      // jsonpFunction: `webpackJsonp_${name}`,
    },
    resolve: {
      alias: {
        "@": path.join(__dirname, "./src"),
      },
    },
  },
  chainWebpack: config => {
    config.plugin("html").tap(args => {
      args[0].title = "leetcode desktop";
      return args;
    });
  },
  runtimeCompiler: true,
};
